
public class DataStructure {

	public static void main(String[] args) {
		P(new char[]{'a','b','c'}, 0, 2);
	}
	
	public static void P(char[] s,int k,int n){
		if(k == n){
			for(char c: s){
				System.out.print(c);
			}
			System.out.println();
		}else{
			for(int i  = k;i <= n;i++ ){
				swap(s,i,k);
				P(s, k+1, n);
				swap(s,k,i);
			}
		}
	}

	private static void swap(char[] s, int k, int i) {
		char temp = s[k];
		s[k] = s[i];
		s[i] = temp;
	}

}
